package main.java.com.extract;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @description:    部门
 * 重构步骤：
 *  1、新建一个超类Party，并将现有的两个类定义为其子类
 *  2、将name字段上移至超类，并将字段取值也上移至超类
 *  3、通常会将这个字段声明为private，不过，在此之前，需要先使用 Pull Up Constructor Body，这样才对name正确赋值
 * @author:         cong zhi
 * @createDate:     2022/6/14 7:55
 * @updateUser:     cong zhi
 * @updateDate:     2022/6/14 7:55
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
public class Department {

    private String name;

    private Vector staff = new Vector();

    public Department(String name) {
        this.name = name;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Enumeration getStaff() {
        return staff.elements();
    }

    public void setStaff(Vector staff) {
        this.staff = staff;
    }

    public int getTotalAnnualCost() {
        Enumeration e = getStaff();
        int result = 0;
        while (e.hasMoreElements()) {
            Employee each = (Employee) e.nextElement();
            result += each.getAnnualCost();
        }
        return result;
    }

    public int getHeadCount() {
        return staff.size();
    }

    public void addStaff(Employee arg) {
        staff.addElement(arg);
    }
}
